package com.atguigu.gulimall.order.web;

import com.alipay.api.AlipayApiException;
import com.atguigu.gulimall.order.config.AlipayTemplate;
import com.atguigu.gulimall.order.service.OrderService;
import com.atguigu.gulimall.order.vo.AlipayVO;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * @Author baiWT
 * @Description
 * @Date 2022/4/13 12:34
 **/
@Controller
public class PayController {

    @Resource
    private OrderService orderService;

    @Resource
    private AlipayTemplate alipayTemplate;

    @ResponseBody
    @GetMapping(value = "/pay/{orderSn}",produces = "text/html")
    public String OrderPay(@PathVariable String orderSn) throws AlipayApiException {

        AlipayVO alipayVO = orderService.OrderPay(orderSn);
        String alipay = alipayTemplate.pay(alipayVO);
        System.out.println(alipay);
        return alipay;
    }
}
